package com.westa.smallshop.util;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.westa.smallshop.common.BaseFragment;

/**
 * Created by Dune on 16/8/25.
 */
public class AMapLocationUtil implements AMapLocationListener {

    public AMapLocationClient mLocationClient;
    private BaseFragment mBaseFragment;

    public AMapLocationUtil(BaseFragment baseFragment) {

        mBaseFragment = baseFragment;
        mLocationClient = new AMapLocationClient(mBaseFragment.getContext());
        mLocationClient.setLocationListener(this);
        AMapLocationClientOption mAMapLocationClientOption = new AMapLocationClientOption();

        mAMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        mAMapLocationClientOption.setOnceLocation(true);
        mLocationClient.setLocationOption(mAMapLocationClientOption);
    }

    public void start() {

        mLocationClient.startLocation();
    }

    @Override
    public void onLocationChanged(com.amap.api.location.AMapLocation aMapLocation) {

        if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {

        } else {

        }
        mLocationClient.onDestroy();
    }
}
